package com.lz.ionicbase.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lz.ionicbase.R;
import com.lz.ionicbase.ui.activity.SetActivity;
import com.lz.ionicbase.utils.Constant;
import com.lz.ionicbase.utils.SpUtils;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by lenovo on 2017/2/4.
 */
public class UserFragment extends BaseFragment implements View.OnClickListener {
    @InjectView(R.id.my_back)
    ImageView myBack;
    @InjectView(R.id.my_set_img)
    ImageView mySetImg;
    @InjectView(R.id.user_layout)
    RelativeLayout userLayout;
    @InjectView(R.id.my_set_layout)
    RelativeLayout mySetLayout;
    @InjectView(R.id.my_user_lasttwo)
    TextView myUserLasttwo;
    @InjectView(R.id.my_username)
    TextView myUsername;
    private SpUtils sp;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_my, null);
        ButterKnife.inject(this, view);
        initView();
        OnInitListener();
        return view;
    }

    private void initView() {
        sp = new SpUtils();
        String username = sp.getString(getActivity(), Constant.USERNAME, "");
        String subsusername = "";
        try {
            subsusername = username.substring(username.length()-2);
        } catch (Exception e) {
            e.printStackTrace();
        }
        myUserLasttwo.setText(subsusername);
        myUsername.setText(username);
    }

    private void OnInitListener() {
        userLayout.setOnClickListener(this);
        mySetLayout.setOnClickListener(this);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.user_layout:
//                Intent personintent = new Intent(getActivity(), BaseWebViewActivity.class);
//                String netUrl = sp.getString(getActivity(), Constant.NET_URL, "");
//                personintent.putExtra("url", netUrl + Constant.PERSONURL);
//                startActivity(personintent);
                break;
            case R.id.my_set_layout:
                Intent intent = new Intent(getActivity(), SetActivity.class);
                startActivity(intent);
                break;
            default:
                break;
        }
    }
}
